<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class ST_Controller extends CI_Controller{
    public function __construct() {
        parent::__construct();

        /** 加载后台控制器公共库 */
        $this->load->library('session');
        $this->load->helper('cookie');

    }
}

/**
 * 后台父控制器
 *
 * 后台所有控制器都需要继承这个类， 包含验证
 */
class Auth_Controller extends ST_Controller{
    public $luser;  //登陆数据

    public function __construct() {
        parent::__construct();

        //判断登陆
        if(empty($_SESSION['user']['id'])){
            $this->session->set_flashdata('err', '您还没有登陆，或者登陆过期');
            redirect(site_url('welcome/index'));
        }

       // if(empty(get_cookie('conf_uptime'))){
            $this->load->model('settings_mdl');
            $this->settings_mdl->set_conf();
      // }
    }

    /**
     * 视图加载
     */
    protected function _view($str,$data=array()){

        $c = $this->uri->segment(1, 0);

        $this->load->view('default/layout/head',$data);
        $this->load->view("default/$c/".$str);
        $this->load->view('default/layout/bottom');
    }

    /** 邮件通知（通知管理员） */
    /**
     * 邮件通知
     * @param  $to      收信人邮箱
     * @param  $title   邮件标题
     * @param  $content 邮件内容
     */
    protected function send_admin($to,$title,$content){

        $this->load->library('email');

        //设置发信人email地址和名称
        $this->email->from('zbzmall@yeah.net', $this->session->config->title, $this->session->config->email);
        //设置邮件回复地址
        $this->email->reply_to($this->session->config->email, $this->session->config->title);
        //设置发送地址
        $this->email->to($to);

        $this->email->subject($title);//主题
        $this->email->message($content); //内容

        return $this->email->send();
    }

    function send_post($url,$post_data) {

        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postdata,
            'timeout' => 15 * 60 // 超时时间（单位:s）
        )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);

        return $result;
    }

}
